// pages/logistics/logistics.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    value: '',
    express_info: [],
    company_name: '',
    express_sn: '',
    thumb: '',
    tel: '',
    status_name: '',
    api: '',
    id: '',
    order_express_id:'',
    for_goods:false
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    console.log(options);
    if (options.fromGrab && options.fromGrab == 1) {
      if (options.api) {
        this.setData({
          api: options.api
        });
      }
    } else {
      if (options.api) {
        this.setData({
          api: options.api
        });
      }else{
        this.setData({
          api: 'dispatch.express'
        });
      }
    }
    if (options.id) {
      this.setData({
        id: options.id
      });
    }
    if (options.order_express_id) {
      this.setData({
        order_express_id: options.order_express_id
      });
    }
    this.getExpress();
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {

  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {

  },

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function() {

  },

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function() {

  },

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function() {

  },

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function() {

  },

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {

  },
  cutPackage(e){
    let item = e.currentTarget.dataset.item;
    console.log(item,'ddd')
    this.setData({
      order_express_id:item,
    })
    this.getExpress();
  },
  getExpress() {
    let that = this;
    let urlStr = app.getNetAddresss(that.data.api);
    let json={order_id:this.data.id,order_express_id:this.data.order_express_id};
    if(this.options.from && this.options.from=="userReturn"){
      delete json.order_id;
      delete json.order_express_id;
      json.refund_id = this.options.refund_id;
      urlStr = app.getNetAddresss("refund.express.user-return");
    }else if(this.options.from && this.options.from=="resend"){
      delete json.order_id;
      delete json.order_express_id;
      json.refund_id = this.options.refund_id;
      json.express_id = this.options.express_id;
      urlStr = app.getNetAddresss("refund.express.resend");
    }
    app._getNetWork({
      url: urlStr,
      data:json,
      success: (resdata)=> {
        var res = resdata.data;
        if (res.result == 1) {
          var myData;
          if(this.data.api == 'dispatch.express'){
            myData = res.data.data;
            this.setData({
              for_goods:res.data.for_goods,
              packageList:res.data.package
            })
          }else{
            myData = res.data;
          }
          that.setData({
            company_name: myData.company_name,
            express_sn: myData.express_sn,
            express_info: myData.data || [],
            tel: myData.tel,
            status_name: myData.status_name,
            thumb: myData.thumb
          });
        } else {
          app.tips(res.msg);
        }

      },
      fail: function(res) {

      }
    });
  },
  copyorderbtn(e) {
    let copydata = e.currentTarget.dataset.copydata;
    if (copydata) {
      wx.setClipboardData({
        data: copydata ? copydata : '',
        success(res) {
          wx.showToast({
            icon: 'none',
            title: '复制成功',
            duration: 1000
          });
        }
      });
    }
  }
});
